<?php 
class Booms extends CI_Controller{
	
	// show all product
	function index(){
		$this->load->model('booms_model');
		$this->load->library('pagination');
		
		$config['base_url']='http://localhost/ci/index.php/booms/index/';
		$config['total_rows']=100;
		$config['per_page']=20;
		$this->pagination->initialize($config); 
		
		$data['rs'] = $this->booms_model->Display($this->uri->segment(3,0),$config['per_page']);
		
		$data['fcnam'] = $this->booms_model->FcNam();
		$data['fcnu'] = $this->booms_model->FcNu();
		$data['ftbrand'] = $this->booms_model->FilterBrand();
		$data['ftmaterial'] = $this->booms_model->FilterMaterial();
		

     	$this->load->view('booms_view',$data); 	
	}
	
	// show all sale
	function sale(){
		$this->load->model('booms_model');
		$this->load->library('pagination');
		
		$config['base_url']='http://localhost/ci/index.php/booms/sale/';
		$config['total_rows']=100;
		$config['per_page']=20;
		$this->pagination->initialize($config); 
		
		$data['rs'] = $this->booms_model->SaleShow($this->uri->segment(3,0),$config['per_page']);
		
		$data['fcnam'] = $this->booms_model->FcNam();
		$data['fcnu'] = $this->booms_model->FcNu();
		$data['ftbrand'] = $this->booms_model->FilterBrand();
		$data['ftmaterial'] = $this->booms_model->FilterMaterial();

     	$this->load->view('booms_view',$data); 	
	}
		
	function add(){
		$this->load->model('booms_model');
		$this->load->helper('html');
		$this->load->helper('form');
		
		$data['sizeChar']=array('S','M','L','XL','XXL');
		$data['sizeNumb']=array('27','28','29','30','31','32','33','34','38','39','40','41','42','43');
		
		$data['fcnam'] = $this->booms_model->FcNam();
		$data['fcnu'] = $this->booms_model->FcNu();
		$data['ftbrand'] = $this->booms_model->FilterBrand();
		
		
		$this->load->view('booms_add_view',$data); 	
	}
	function create(){
		$this->load->model('booms_model');
		
		$string="";
		if(isset($_POST['check'])){
			foreach($_POST['check'] as $item){
				if($item!=end($_POST['check'])){
					$string=$string.$item.", ";
				}else{
					$string=$string.$item;
				}
			}
		}
		
		$data = array('p_name'=>$this->input->post('pName'),
					  'p_code'=>$this->input->post('pCode'),
					  'pcat_code'=>$this->input->post('pCatCode'),
					  'p_des'=>$this->input->post('pDes'),
					  'date'=>$this->input->post('pDate'),
					  'brandcode'=>$this->input->post('pBrand'),
					  'material'=>$this->input->post('pMaterial'),
					  'size'=>$string,
					  'color'=>$this->input->post('pColor'),
					  'status'=>$this->input->post('pStatus'),
					  'price'=>$this->input->post('pPrice'),
					  'is_hot'=>$this->input->post('pIsHot'),
					  'is_home'=>$this->input->post('pIsHome'),
					  'is_sale'=>$this->input->post('pIsSale'),
					  'sale_type'=>$this->input->post('pSaleType'),
					  'sale_value'=>$this->input->post('pSaleValue')
		);
		$this->booms_model->addProduct($data);
		$this->index();
		
	}
	function editSale(){
		$this->load->model('booms_model');
		$data=array(
			'is_sale'=>$this->input->post('txtIsSale'),
			'sale_type'=>$this->input->post('txtSaleType'),
			'sale_value'=>$this->input->post('txtSaleValue')
		);		
		if(isset($_POST['idList'])){
			$idList = array();
			$idList=unserialize($_POST['idList']);
			$this->booms_model->updateSale($data,$idList);
		}
		$this->index();
	}
	
	function updateView(){
		$this->load->model('booms_model');
		$this->load->helper('html');
		$this->load->helper('form');
		
		$data['sizeChar']=array('S','M','L','XL','XXL');
		$data['sizeNumb']=array('27','28','29','30','31','32','33','34','38','39','40','41','42','43');
		$data['rsonce'] = $this->booms_model->getOnceProduct($this->uri->segment(3));
		$data['fcnam'] = $this->booms_model->FcNam();
		$data['fcnu'] = $this->booms_model->FcNu();
		$data['ftbrand'] = $this->booms_model->FilterBrand();
		
		$this->load->view('booms_update_view',$data);		 	
		
	}
	
	function update(){
		
		$this->load->model('booms_model');
		
		$string="";
		if(isset($_POST['check'])){
			foreach($_POST['check'] as $item){
				if($item!=end($_POST['check'])){
					$string=$string.$item.", ";
				}else{
					$string=$string.$item;
				}
			}
		}
		
		
		$data = array('p_name'=>$this->input->post('pName'),
					  'p_code'=>$this->input->post('pCode'),
					  'pcat_code'=>$this->input->post('pCatCode'),
					  'p_des'=>$this->input->post('pDes'),
					  'date'=>$this->input->post('pDate'),
					  'brandcode'=>$this->input->post('pBrand'),
					  'material'=>$this->input->post('pMaterial'),
					  'p_id'=>$this->input->post('pId'),
					  'size'=>$string,
					  'color'=>$this->input->post('pColor'),
					  'status'=>$this->input->post('pStatus'),
					  'price'=>$this->input->post('pPrice'),
					  'is_hot'=>$this->input->post('pIsHot'),
					  'is_home'=>$this->input->post('pIsHome'),
					  'is_sale'=>$this->input->post('pIsSale'),
					  'sale_type'=>$this->input->post('pSaleType'),
					  'sale_value'=>$this->input->post('pSaleValue')
		);
		$id=$this->input->post('pId');
		$this->booms_model->updateProduct($data,$id);
		$this->index();	
	}
}
?>